
#include "stdafx.h"
#include <allegro5/allegro_primitives.h>
#include "BaseComponent.h"

BaseComponent::BaseComponent(const char * modelName) :
	_modelName( modelName ) {
  // Bouml preserved body begin 0001F47B
	_angle = 0.0;
  // Bouml preserved body end 0001F47B
}

BaseComponent::~BaseComponent(void ){
  // Bouml preserved body begin 0001F4FB
  // Bouml preserved body end 0001F4FB
}

//Loads figure from array of points.
//Array should hold numPoints * 2 floats.
void BaseComponent::LoadFigure(int numPoints, const float * listPoints) {
  // Bouml preserved body begin 0002347B
	_figure.clear();
	_figure.resize( numPoints );
	for (int i = 0; i < numPoints; i++ ) {
		_figure[i].x = listPoints[ i * 2];
		_figure[i].y = listPoints[ i * 2 + 1];
	}
  // Bouml preserved body end 0002347B
}

void BaseComponent::SetAngle(float angle) {
  // Bouml preserved body begin 00024F7B
	_angle = angle;
  // Bouml preserved body end 00024F7B
}

//Draws object in given position

void BaseComponent::DrawAt(const BaseComponent::point & position) {
  // Bouml preserved body begin 00024FFB
	ALLEGRO_TRANSFORM current, toUse;

	al_copy_transform( &current, al_get_current_transform() );
	al_identity_transform( &toUse );
	al_rotate_transform( &toUse, _angle );
	al_translate_transform( &toUse, position.x, position.y );
	al_compose_transform( &toUse, &current );
	al_use_transform( &toUse );

    if ( _figure.size() > 1 ) {
        for ( int i = 0; i < _figure.size() - 1; i++ ) {
            al_draw_line(
				_figure[ i].x,
				_figure[ i].y,
				_figure[ i+1].x,
				_figure[ i+1].y,
				al_map_rgb( 255, 255, 255 ), 1 );
        }
        al_draw_line(
			_figure[ 0].x,
			_figure[ 0].y,
			_figure[ _figure.size()-1].x,
			_figure[ _figure.size()-1].y,
			al_map_rgb( 255, 255, 255 ), 1 );
    }

	al_use_transform( &current );
  // Bouml preserved body end 00024FFB
}

